#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 1e2 + 5, inf = 0x3f3f3f3f, M = 1605;
int q, n, a[N], b[N], f[N][N][M];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("box.in", "r", stdin);
  freopen("box.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  int tot = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    if (a[i]) tot++;
  }
  for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); }
  memset(f, -inf, sizeof(f));
  f[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int v = 0; v < M; v++) {
        f[i][j][v] = std::max(f[i][j][v], f[i - 1][j][v]);
        if (j && v >= b[i] - a[i])
          f[i][j][v] =
              std::max(f[i][j][v], f[i - 1][j - 1][v - (b[i] - a[i])] + a[i]);
      }
    }
  }
  scanf("%d", &q);
  for (int i = 1, k, ans; i <= q; i++) {
    scanf("%d", &k);
    ans = inf;
    for (int v = 0; v < M; v++)
      if (sum - f[n][k][v] <= v) ans = std::min(ans, sum - f[n][k][v]);
    if (ans == inf) puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}